﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.IBLL;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.Common
{
	public partial class AresByUserId : System.Web.UI.UserControl
	{

		protected void Page_Load(object sender, EventArgs e)
		{

		}

		/// <summary>
		/// 曹鹏
		/// 2011年5月16日15:09:56
		/// 地区绑定
		/// </summary>
		private void AreaDataBind()
		{
			IBLL_Area ia = new HZ.Supervise.BLL.BLL_Area();
			IList<Area> lstArea = new List<Area>();
			string userAreaId = CurrentAccount.GetUser().Org.Area.AreaID;
			//判断用户所属地区，如果用户是省级的 则可以列出全部区域
			if (userAreaId == CurrentAccount.GetCurrentDeployArea().AreaID)
			{
				lstArea = ia.GetSonAreas(userAreaId);
				foreach (Area area in lstArea)
				{
					if (area.AreaName == "省直属")
					{
						ListItem item = new ListItem();
						item.Text = area.AreaName;
						item.Value = area.AreaID;
						ddlCity.Items.Insert(0, item);
					}
					else
					{
						ListItem ddlitem = new ListItem();
						ddlitem.Text = area.AreaName;
						ddlitem.Value = area.AreaID;
						ddlCity.Items.Add(ddlitem);
					}
				}

				//ListItem a = new ListItem();
				//a.Text = "省直属";
				//a.Value = userAreaId;
				//ddlCity.Items.Insert(0, a);

				ListItem b = new ListItem();
				b.Text = "全部";
				b.Value = "";
				ddlCity.Items.Insert(0, b);
			}
			else
			{
				lstArea = ia.GetAreasByAreaID(userAreaId);
				foreach (Area area in lstArea)
				{
					ListItem ddlitem = new ListItem();
					ddlitem.Text = area.AreaName;
					ddlitem.Value = area.AreaID;
					ddlCity.Items.Add(ddlitem);
				}
			}
			//绑定数据源
			//如果有当前省的编号，则增加省直属 
			//同时地区获取值的要设置 

			//绑定区县
			ddlCity_SelectedIndexChanged(null, null);

		}

		protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
		{
			string strCity = (this.ddlCity.SelectedItem != null) ? this.ddlCity.SelectedItem.Value : "";

			this.ddlCountry.Items.Clear();

			IBLL_Area ia = new HZ.Supervise.BLL.BLL_Area();
			IList<Area> lstArea = new List<Area>();
			if (!string.IsNullOrEmpty(strCity))
			{
				lstArea = ia.GetSonAreas(strCity);

				foreach (Area area in lstArea)
				{
					ListItem ddlitem = new ListItem();
					ddlitem.Text = area.AreaName;
					ddlitem.Value = area.AreaID;
					this.ddlCountry.Items.Add(ddlitem);
				}
			}

			ListItem b = new ListItem();
			b.Text = "所在区县";
			b.Value = "";
			ddlCountry.Items.Insert(0, b);
		}
	}
}